from time import sleep
from base_page.basepage import BasePage
import allure

'''
此模块进行了封装了钱包模块的部分定位元素以及操作层  为了更到的维护整个项目的测试
框架，后期只需要对对象层元素定位进行增加以及修改

对象方法 find_element_if方法在page文件中进行了封装根据传参形式来怕判断进行使用那个获取元素的方法
'''


# 对象层
class WalletGdPage(BasePage):
    def __init__(self,type="app"):
        super().__init__(type)

    # 获取钱包按钮
    @allure.step("钱包按钮")
    def find_wallet(self):
        return self.find_elements_if("css", ".am-tab-bar-tab-title", -2)
        # return self.driver.find_elements_by_css_selector(".am-tab-bar-tab-title")[0]

    # 定位获取人保钱包选项
    @allure.step('人保钱包')
    def find_wallet_rb(self):
        return self.find_element_if("xpath", ".//*[@id='app-root']/div/div[2]/div/div[2]/div[2]/div/div/div[2]")

    # 定位获取光大钱包
    @allure.step('光大钱包')
    def find_wallet_gd(self):
        return self.find_element_if("id", "guangda")

    # 定位获取眼睛按钮
    @allure.step('眼睛按钮')
    def find_wallet_eye(self):
        return self.find_element_if("id", "eyes2")

    # 定位获取余额
    @allure.step('余额')
    def find_wallet_sum(self):
        return self.find_element_if("id", "money1")

    # 定位光大银行字体
    @allure.step('钱包右上角字体')
    def find_text(self):
        return self.find_element_if("xpath",
                                    '//*[@id="app-root"]/div/div[3]/div/div[2]/div[1]/div/div/div/div[2]/div[1]/span')

    # 充值按钮钱包--充值
    @allure.step('钱包充值选项')
    def find_tupup(self):
        return self.find_element_if("xpath", '//*[@id="app-root"]/div/div[3]/div/div[2]/a[1]/div')

    @allure.step("输入金额")
    def find_input_money(self):
        return self.find_element_if('css', '[placeholder="请输入充值金额"]')

    # 充值按钮钱包--充值--充值
    @allure.step('充值按钮')
    def find_tupup_tupop(self):
        return self.find_element_if("xpath", '//*[@id="app-root"]/div/div[5]/a')

    # 充值银行卡
    @allure.step('点击银行卡')
    def find_tupup_bank(self):
        return self.find_element_if("xpath", '//*[@id="app-root"]/div/div[3]/div/div[1]/div[1]/div[1]')

    @allure.step("提示toast")
    def find_toast(self):
        return self.find_element_if("xpath", '/html/body/div[2]/div/span/div/div/div/div')

    # 提现按钮
    @allure.step('提现按钮')
    def find_deposit(self):
        return self.find_element_if("xpath", '//*[@id="app-root"]/div/div[3]/div/div[2]/a[2]/div')

    # 账单按钮
    @allure.step('账单按钮')
    def find_bill(self):
        return self.find_element_if('xpath', '//*[@id="app-root"]/div/div[3]/div/div[2]/a[3]/div')

    # 银行卡按钮
    @allure.step('银行卡按钮')
    def find_bank(self):
        return self.find_element_if('xpath', '//*[@id="app-root"]/div/div[3]/div/div[2]/a[4]/div')

    # 添加银行卡
    @allure.step('添加银行卡')
    def find_add_bank(self):
        return self.find_element_if('xpath', '//*[text() = "添加银行卡"]')

    @allure.step('输入银行卡号')
    def find_bankcard(self):
        return self.find_element_if('name', 'bankCard')

    @allure.step('下一步')
    def find_next(self):
        return self.find_element_if('xpath', '//*[text() = "下一步"]')

    @allure.step('卡类型')
    def find_bank_type(self):
        return self.find_element_if('name', 'bankAndCardType')

    @allure.step('账户安全险')
    def find_asfe(self):
        return self.find_element_if("xpath", "//*[text() = '账户安全险']")

    @allure.step('申请理赔')
    def find_claim(self):
        return self.find_element_if("xpath", "//*[text() = '申请理赔']")

    @allure.step('工作时间')
    def find_time(self):
        return self.find_element_if("xpath", "//*[contains(text(), '周一到周')]")

    @allure.step('联系电话')
    def find_phone(self):
        return self.find_element_if("xpath", "//*[contains(text(), '400')]")

    @allure.step('保险条款')
    def find_clause(self):
        return self.find_element_if("xpath", "//*[contains(text(), '保险条款')]")


class WalletHandle(object):
    def __init__(self):
        self.page = WalletGdPage()

    def click_wallet(self):
        self.page.find_wallet().click()

    def click_wallet_rb(self):
        self.page.find_wallet_rb().click()

    def click_wallet_gd(self):
        self.page.find_wallet_gd().click()

    def click_wallet_eye(self):
        self.page.find_wallet_eye().click()

    def click_find_tupup(self):
        self.page.find_tupup().click()

    def click_find_tupup_tupup(self):
        self.page.find_tupup_tupop().click()

    def send_keys_money(self, num):
        self.page.find_input_money().send_keys(num)

    def click_tupup_bank(self):
        self.page.find_tupup_bank().click()

    # 点击银行卡
    def click_bank(self):
        self.page.find_bank().click()

    # 点击添加银行卡
    def click_add_bank(self):
        self.page.find_add_bank().click()

    # 输入银行卡号
    def send_keys_bank(self, num):
        self.page.find_bankcard().send_keys(num)

    # 点击下一步
    def click_next(self):
        self.page.find_next().click()

    # 点击眼睛
    def click_eye(self):
        self.page.find_wallet_eye().click()

    # 点击账户安全险
    def click_asfe(self):
        self.page.find_asfe().click()

    # 点击申请理赔
    def click_claim(self):
        self.page.find_claim().click()

    # 点击保险条款
    def click_clause(self):
        self.page.find_clause().click()


# 逻辑层
class WalletProxy(object):
    def __init__(self):
        self.handle = WalletHandle()

    # 进入光大钱包
    def wallet(self):
        self.handle.click_wallet()
        sleep(2)
        self.handle.click_wallet_rb()
        sleep(2)
        self.handle.click_wallet_gd()

    # 充值金额为空
    def wallet_none(self):
        self.handle.click_wallet()  # 点击钱包
        sleep(2)
        self.handle.click_wallet_rb()  # 点击人保
        sleep(2)
        self.handle.click_wallet_gd()  # 点击光大
        sleep(2)
        self.handle.click_find_tupup()  # 点击充值
        sleep(2)
        self.handle.click_find_tupup_tupup()  # 点击充值---充值

    # 充值金额元  可以进行多次调用
    def wallet_xxx(self, num):
        self.handle.click_wallet()  # 点击钱包
        sleep(2)
        self.handle.click_wallet_rb()  # 点击人保
        sleep(2)
        self.handle.click_wallet_gd()  # 点击光大
        sleep(2)
        self.handle.click_find_tupup()  # 点击充值
        sleep(2)
        self.handle.send_keys_money(num)  # 输入金额
        sleep(2)
        self.handle.click_find_tupup_tupup()  # 点击充值--充值

    # 充值点击银行卡
    def bank_click(self):
        self.handle.click_wallet()  # 点击钱包
        sleep(2)
        self.handle.click_wallet_rb()  # 点击人保
        sleep(2)
        self.handle.click_wallet_gd()  # 点击光大
        sleep(2)
        self.handle.click_find_tupup()  # 点击充值
        sleep(2)
        self.handle.click_tupup_bank()  # 点击选择银行卡

    # 银行卡--添加银行卡
    def add_bank(self, num):
        self.handle.click_wallet()  # 点击钱包
        sleep(2)
        self.handle.click_wallet_rb()  # 点击人保
        sleep(2)
        self.handle.click_wallet_gd()  # 点击光大
        sleep(2)
        self.handle.click_bank()  # 点击银行卡
        sleep(2)
        self.handle.click_add_bank()  # 点击添加银行卡
        sleep(2)
        self.handle.send_keys_bank(num)  # 输入银行卡号
        sleep(2)
        self.handle.click_next()  # 点击下一步

    # 获取光大钱包余额
    def get_money(self):
        self.handle.click_wallet()  # 点击钱包
        sleep(2)
        self.handle.click_wallet_rb()  # 点击人保
        sleep(2)
        self.handle.click_wallet_gd()  # 点击光大
        sleep(2)
        self.handle.click_eye()  # 点击眼睛

    def get_time(self):
        self.handle.click_wallet()  # 点击钱包
        sleep(2)
        self.handle.click_asfe()     # 点击账户安全险
        sleep(2)
        self.handle.click_claim()    #点击申请理赔
    def get_clause(self):
        self.handle.click_wallet()  # 点击钱包
        sleep(2)
        self.handle.click_asfe()     # 点击账户安全险
        sleep(2)
        self.handle.click_clause()   #点击保险条款
if __name__ == '__main__':
    WalletProxy().wallet()
